package com.click.app.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Joel Chuca Condo
 * @date 07/04/2009
 */
@Entity(name="laundry_payments")
public class LaundryPayment extends BaseObject {

    private Long id;
    private Float amount;
    private Date date;
    private String code;

    private List<LaundryRequestLaundryPayment> laundryRequestLaundryPayments =
                                                new ArrayList<LaundryRequestLaundryPayment>();

    PeriodPaymentLaundry periodPaymentLaundry;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id_laundry_payment")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "amount")
    public Float getAmount() {
        return this.amount;
    }

    public void setAmount(Float amount) {
        this.amount = amount;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "date")
    public Date getDate() {
        return this.date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Column(name = "code", length = 50)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "laundryPayment")
    public List<LaundryRequestLaundryPayment> getLaundryRequestLaundryPayments() {
        return laundryRequestLaundryPayments;
    }

    public void setLaundryRequestLaundryPayments(List<LaundryRequestLaundryPayment> laundryRequestLaundryPayments) {
        this.laundryRequestLaundryPayments = laundryRequestLaundryPayments;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_period_payment_laundry", nullable = false)
    public PeriodPaymentLaundry getPeriodPaymentLaundry() {
        return periodPaymentLaundry;
    }

    public void setPeriodPaymentLaundry(PeriodPaymentLaundry periodPaymentLaundry) {
        this.periodPaymentLaundry = periodPaymentLaundry;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }


    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LaundryPayment)) {
            return false;
        }
        LaundryPayment other = (LaundryPayment) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.sodes.app.model.ReceiptPayment[id=" + id + "]";
    }
}
